Skip to content

ZeroTier page under Settings → VPN - #989

Merged
dormancygrace merged 15 commits into
dormancygrace:mainfrom
Msprg:zerotier/settings
Nov 23, 2026
Merged

dormancygrace merged 15 commits into
dormancygrace:mainfrom
Msprg:zerotier/settings

Conversation

@Msprg

@Msprg Msprg commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Refs #981. This is the second half, after the package in #985: a ZeroTier page under Settings → VPN, next to Tailscale and NetBird.

What it does

  • Install: installs nanokvm-zerotier from the add-on repository the same way the OCR models are installed (apkpkg.InstallOnly), so an install that would upgrade, downgrade or remove another package is refused.
  • Start and stop: Start adds zerotier-one to the default runlevel and starts it; Stop does the reverse. The daemon is started without the server's OOM protection.
  • Status: the node ID (copyable), whether the node is online, the version, and the joined networks with their name, status, device and assigned addresses. It's read from zerotier-cli -j info and -j listnetworks, stdout only, so a warning on stderr can't break the parse. The page polls every 5 s while visible.
  • Join and leave: by 16-digit network ID. The server lowercases and checks the ID against ^[0-9a-f]{16}$ before anything reaches zerotier-cli. A network that still needs authorization shows Not authorized.
  • Uninstall: stops and removes the package. /var/lib/zerotier-one (identity and networks) is kept unless you choose to delete it.
  • Elsewhere:
    • zerotier-one is an optional service in Diagnostics.
    • The VPN list shows ZeroTier with its first IPv4 address.
    • The package has a "ZeroTier" label in package updates.
    • The VPN version list knows zerotier-one -v.
  • Backups: identity.secret, identity.public, local.conf and networks.d/ are in the settings backup for Restore this device. They're never copied by migration, because two devices with one identity break each other. authtoken.secret, peers and the planet file aren't settings and stay out.

The page uses a generic lucide icon, not ZeroTier's logo. Only en.json has the new strings, and the other languages fall back to English until Weblate catches up.

How I checked it

  • Go: build, vet and tests with teststub,nomsgpack. The only failure is the remotemedia SMB test, which fails the same way without these changes, because memfd isn't available under WSL.

  • New Go tests: the network ID check, the JSON parsers, the IPv4 pick, and the backup policy for the ZeroTier paths.

  • Web: format:check, build, lint and the web tests (37 pass).

  • On a NanoKVM Lite with the nanokvm-zerotier: ZeroTier One 1.16.2 as an optional add-on #985 package:

    • The JSON from the real zerotier-cli -j info and -j listnetworks parses correctly with these parsers.
    • Join and leave with a dummy network ID, start, stop and uninstall all work the way the server drives them.
  • The page on the device: NanoKVM OS 4.2.1 with this PR's server and web commits on top, built against the device's own libkvm/libkvm_mmf, and driven in a browser:

    • The VPN list and the Dashboard show ZeroTier as connected, with its address.
    • The page shows the status, the node ID, the version, and the network with its name, state and address.
    • An invalid network ID keeps Join disabled. An upper-case ID is lowercased. A dummy network goes to "Requesting configuration", and Leave removes it.
    • Restart goes through "Connecting" back to "Online". Stop takes it out of the runlevel, and Start puts it back.
    • Uninstall with "delete identity" unticked keeps /var/lib/zerotier-one. Install (from a temporary signed local repository, since the add-on isn't on Pages yet), then Start, comes back with the same node ID and network.
    • Diagnostics lists zerotier-one as an optional running service.
    • After the review fixes: Uninstall under a held update lock and with a failing apk del, a second Stop, and the poll under 6.5 s latency (details in the review replies).

    Afterwards the device went back to the stock 4.2.1 server and web files.

Msprg and others added 3 commits November 22, 2026 16:31
Install, start, stop and remove the add-on, join and leave networks, and
report the node, its networks and their addresses from zerotier-cli's JSON
(stdout only, so a warning on stderr cannot break the parse). The identity
and joined networks are in the settings backup for restoring this device,
never for migration.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@dormancygrace dormancygrace left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requested changes after reviewing the package lifecycle, restore policy and settings page. A temporary-root Go check confirmed deletion of an existing identity in the restore plan for a legacy same-device backup. Focused Go tests and vet, the production web build and lint passed; the GitHub checks for this head also passed. The restore compatibility and service lifecycle issues need fixes before merge.

Comment thread server/recovery/policy.go Resolved
Msprg and others added 3 commits November 22, 2026 17:05
A backup now lists the settings groups it covers (ZeroTier, the first).
Restoring one made before a group existed leaves that group's files as
they are, in the plan and in the boot pass that takes inventory again,
instead of deleting the identity and networks it never recorded. A
backup that covers ZeroTier still restores its recorded state.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…level failures

Uninstall stops ZeroTier inside apkpkg.RemoveAfter, under the package
lock: while another update holds it, ZeroTier keeps running and stays in
the boot runlevel. If apk then fails, it is started again and put back
in the runlevel as it was. Stop treats a service already out of the
runlevel as success and reports a failure to take it out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A poll tick is skipped while a request is on its way, so slow answers
are no longer dropped by the next tick; a refresh after an action reads
once more after it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@dormancygrace dormancygrace left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified and resolved the four earlier findings on this revision: importing an old backup with the new code preserves the identity, package lock contention now precedes service shutdown, Stop propagates runlevel failures, and slow status polls coalesce. Two additional paths still risk losing a working ZeroTier identity or connection. Both are detailed inline with isolated reproductions. Focused Go tests and vet, web build and lint, a slow-response polling check, and all applicable CI jobs passed.

Comment thread server/recovery/engine.go Resolved
Msprg and others added 2 commits November 22, 2026 17:26
Plan.Covers replaces Plan.Keep: the groups a plan may change (the
archive's, or all for a reset). A journal without it, as one a release
before groups queued, changes no group's files, in the plan or in the
boot pass, so a restore staged before an upgrade keeps the ZeroTier
identity and networks written before its replay.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RemoveAfter simulates the removal under the lock first and refuses
before prepare when apk would keep a package (apk del exits 0 and keeps
one another selected package needs), then checks after apk del that the
packages are gone, undoing prepare otherwise. ZeroTier's purge runs only
after that.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@dormancygrace dormancygrace left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes for two paths that can still delete the ZeroTier identity. The legacy restore regression is fixed. The removal simulation also correctly rejects a pre-existing reverse dependency before stopping the service. Local race tests and vet passed, along with GitHub CI, CodeQL, the add-on build and the firmware build. The inline findings cover a legacy factory-reset journal and an indeterminate post-removal check.

Comment thread server/recovery/engine.go Resolved
Msprg and others added 5 commits November 22, 2026 18:39
The boot pass prepares a queued reset again, which covered every group
this release knows. A reset queued by a release before groups existed
then deleted the ZeroTier identity that its own boot pass would have
kept. Keep the journal's coverage and drop regenerated changes outside it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The check after apk del took any failure of apk info -e, also a failed
exec or database read, as proof that the package was gone, so a purge
could erase the identity of a node still installed. Read the installed
database instead; an unreadable or empty one fails the removal and
runs the caller's undo.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ServiceRunning ran rc-service without a time limit, so a stuck OpenRC
held every status request. Run it like the other commands, with the
command timeout and a kill of its process group.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A backup taken before ZeroTier ran covered its group anyway, so
restoring it deleted an identity made later, which no backup holds.
Cover a group only when the device has files of it. A group of a later
release now asks for that release instead of failing as invalid.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A running service without a node ID has not answered yet: its networks
are unknown, not none, so say so and keep Join disabled. Drop the
16-character limit on the network ID field, which cut a pasted ID with
surrounding spaces before the trim. Guard a missing error object in
the uninstall modal. VPN.md: installing does not start ZeroTier.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Msprg

Msprg commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Besides the two inline fixes, I went over the whole PR again before pushing. That added three small commits you didn't ask for, so here's what they change:

  • da8f21d changes what a backup means. Snapshot now covers a group only when the device has files in it; before, it covered all of them. A backup taken before ZeroTier ran used to plan, on Restore this device, to delete an identity created later. The preview listed that, but the node ID was gone for good. Now such a backup leaves ZeroTier alone, the same as a backup from before groups existed. A backup that has the identity restores it as before. If you'd rather keep the old meaning, say so and I'll drop the commit.
    • The same commit changes the error for a group this release doesn't know: it now asks for the later application version instead of saying "invalid settings group".
    • VPN.md has a sentence about this.
  • 63bc7de: ServiceRunning runs rc-service zerotier-one status with the command timeout and process-group kill used by the other calls, so a stuck OpenRC can't hold every status request.
  • 0b856e8, page and docs:
    • A running service that hasn't answered yet (no node ID) now says so instead of "No network joined yet", and Join stays disabled.
    • The network ID field no longer has a 16-character limit, which cut off a pasted ID that had spaces around it before the trim.
    • The uninstall modal handles a missing error object.
    • VPN.md no longer says that installing starts the service.

Go vet, the race tests of the touched packages, the full Go suite, the web build and lint, and the test budget all pass locally. The one exception is the remotemedia SMB test, which can't run under WSL.

@dormancygrace dormancygrace left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified the legacy reset fix and the removal helper’s handling of a failed installed-database read and a retained package. Two paths still erase identity state: restoring a backup containing only pre-start configuration, and purging a recorded installation whose binary is missing. Both were reproduced against this revision in isolated roots. Race tests and vet passed for recovery, osupdate, apkpkg and zerotier; CI, CodeQL and both builds passed.

Comment thread server/recovery/engine.go Resolved
Msprg and others added 2 commits November 23, 2026 10:11
A backup taken before ZeroTier first started, with only local.conf or a
preseeded network, covered the whole group, so restoring it deleted the
identity and networks made since. Split the group: the identity and its
networks are covered only when identity.secret was backed up, and their
files stay out otherwise; local.conf is covered when it was backed up
or once ZeroTier had started.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Uninstall took a missing binary for an absent package and purged the
state without the update lock. RemoveAfter now reads the installed
database under the lock: a recorded package is removed even with its
files missing, and the purge runs under the same lock once the package
is gone or was never recorded, never while a ZeroTier from elsewhere is
still there. A recorded package without its program shows as installed
and not running, so the page offers Uninstall, and Start and Install
say how to repair it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@dormancygrace dormancygrace left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified both fixes on ef7a920. A pre-start configuration backup restores local.conf and preserves the later node identity and memberships. In an isolated filesystem with a recorded package and missing executable, a held update lock or failed APK operation now leaves the identity intact. Explicit purge succeeded after confirming package absence. The full server suite passed, with race tests and vet on the four affected packages. Web UI, CodeQL, firmware and add-on CI also passed.

@dormancygrace
dormancygrace merged commit 7b01aad into dormancygrace:main Nov 23, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants